package tr.edu.yildiz.ce.app_manager.ui.components.table;

import java.util.List;

import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.Table;

import tr.edu.yildiz.ce.app_manager.model.AppProxy;
import tr.edu.yildiz.ce.app_manager.model.Application;
import tr.edu.yildiz.ce.app_manager.ui.AppManagerApplication;
import tr.edu.yildiz.ce.app_manager.ui.action.table.ApplicationTableSelectAction;
import tr.edu.yildiz.ce.app_manager.ui.action.table.ProxyTableSelectAction;

public class ProxyTableForm extends BasicTableForm<AppProxy>{

	public ProxyTableForm(AppManagerApplication app_) {
		super( app_);
		
	}

	@Override
	public AppProxy getModel() {
		return new AppProxy();
	}
	
	@Override
	public Table getTable() {
		Table table = new Table();
		List<AppProxy> list = app.getServiceProvider().getAppProxyService().listAll();
		
		table.addContainerProperty("Proxy Name", String.class, null);
		table.addContainerProperty("Proxy Ip", String.class, null);
		table.addContainerProperty("Proxy Parent", String.class, null);
		for (AppProxy appProxy : list) {
			table.addItem(new Object[]{	appProxy.getProxyName(),
										appProxy.getProxyIp(),
										((appProxy.getParent() != null) ? appProxy.getParent().getProxyName():"")},appProxy.getProxyId());
		}
		table.addListener(new ItemClickListener() {
			@Override
			public void itemClick(ItemClickEvent event) {
				ProxyTableSelectAction ptsAction = new ProxyTableSelectAction(app,(Long) event.getItemId());
				ptsAction.doAction();
				selectedObject = ptsAction.getProxy();
			}
		});
		table.setSelectable(true);
		return table;
	}

}
